package com.aaa.service.impl;

import com.aaa.util.MailUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;


@Service
public class MailServiceImpl {

    @Resource
    private RedisTemplate<String,String> redisTemplate;

    public void sendMail(String lemail) throws Exception {
        MailUtils mailUtils = new MailUtils();
//      随机4位数字验证码
        int code = (int) (Math.random() * (9999 - 1000 + 1)) + 1000;
//        将验证码存入redis 时间为3分钟
        redisTemplate.opsForValue().set("eCode", String.valueOf(code), 1, TimeUnit.MINUTES);
        String content =  "<h1>【波点音乐】</h1><h3>"+code+"，（波点音乐注册验证码），请在3分钟内完成注册。如非本人操作，请忽略！</h3>";
        String title = "波点音乐注册验证码";
        mailUtils.sendMail(lemail, title, content);
    }
}
